/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainMenu.java
 *
 * Created on May 7, 2010, 7:44:54 PM
 */

package View;

import Model.Game;
import View.BuildMode.BuildMap;
import View.PlayMode.Play;
import View.PlayMode.SelectPlayer;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;

/**
 *
 * @author  Rezan Achmad
 *          13508104
 */
public class MainMenu extends javax.swing.JFrame {

    /** Creates new form MainMenu */
    public MainMenu() {
        initComponents();
        /* Load game panel */
        load = new LoadGame(this);
        jPanel1.add(load, 0);
        load.setVisible(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        newgameButton = new javax.swing.JButton();
        exitButton = new javax.swing.JButton();
        buildmapButton = new javax.swing.JButton();
        loadGameButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setLayout(null);

        newgameButton.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        newgameButton.setText("New Game");
        newgameButton.setFocusable(false);
        newgameButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                newgameButtonMousePressed(evt);
            }
        });
        jPanel1.add(newgameButton);
        newgameButton.setBounds(530, 380, 120, 25);
        newgameButton.getAccessibleContext().setAccessibleName("newgameButton");

        exitButton.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        exitButton.setText("Exit");
        exitButton.setFocusable(false);
        exitButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                exitButtonMouseClicked(evt);
            }
        });
        jPanel1.add(exitButton);
        exitButton.setBounds(530, 455, 120, 25);
        exitButton.getAccessibleContext().setAccessibleName("exitButton");

        buildmapButton.setFont(new java.awt.Font("Tahoma", 0, 12));
        buildmapButton.setText("Build Map");
        buildmapButton.setFocusable(false);
        buildmapButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                buildmapButtonMouseClicked(evt);
            }
        });
        jPanel1.add(buildmapButton);
        buildmapButton.setBounds(530, 430, 120, 25);

        loadGameButton.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        loadGameButton.setText("Load Game");
        loadGameButton.setFocusable(false);
        loadGameButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loadGameButtonActionPerformed(evt);
            }
        });
        jPanel1.add(loadGameButton);
        loadGameButton.setBounds(530, 405, 120, 25);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 668, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void newgameButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_newgameButtonMousePressed
        this.setVisible(false);
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                play = new Play(me);
//                play.setVisible(true);
//            }
//        });
        new SelectPlayer(this).setVisible(true);
    }//GEN-LAST:event_newgameButtonMousePressed

    private void exitButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_exitButtonMouseClicked
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_exitButtonMouseClicked

    private void buildmapButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_buildmapButtonMouseClicked
        // TODO add your handling code here:
        this.setVisible(false);
        GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice[] devices = env.getScreenDevices();
        buildmap = new BuildMap(this,devices[0]);
    }//GEN-LAST:event_buildmapButtonMouseClicked

    private void loadGameButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadGameButtonActionPerformed
        int x,y,width,height;
        load.initListFile();
        width = load.getPreferredSize().width;
        height = load.getPreferredSize().height;
        x = (jPanel1.getWidth()-width)/2;
        y = 20;
        load.setBounds(x, y, width, height);
        load.setVisible(true);
    }//GEN-LAST:event_loadGameButtonActionPerformed

    /**
    * @param args the command line arguments
    */
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                new MainMenu().setVisible(true);
//            }
//        });
//    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buildmapButton;
    private javax.swing.JButton exitButton;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JButton loadGameButton;
    private javax.swing.JButton newgameButton;
    // End of variables declaration//GEN-END:variables
    private Play play;
    private BuildMap buildmap;
    private MainMenu me=this;
    private LoadGame load;
    private Game game;

    /**
     * @return the game
     */
    public Game getGame() {
        return game;
    }

    /**
     * @param game the game to set
     */
    public void setGame(Game game) {
        this.game = game;
    }
}
